$.extend(planner.mech, {
    pretty_weapons: function ()
    {
        console.log("planner.mech.pretty_weapons()");
        console.log(planner.mech.weapons);
        seen = {};
        list = [];
        
       
        $.each( planner.mech.weapons, function(i, weapon) {
                if( !seen[weapon] )
                seen[weapon] = 0;
          
            seen[weapon]++;
        });
        
        $.each( planner.mech.weapons, function(i, weapon) {
            
            if ( weapon in seen )
            {
                list.push(seen[weapon] + " " + weapon);
                delete seen[weapon];
            }
            
        });
        
        return list;
    },
    save: function(name)
    {
        args = { i:"1", a:"s" };
        
        if (name) {
            args['n'] = name
        }
        
        console.log("planner.mech.save()");
        planner.server.post_mech(
            args,
            function (html) {
                planner.mech.ui.update();
                
                if ( planner.roster.ui.is_visible() )
                {
                    planner.roster.ui.update_html(html);
                    planner.roster.show();
                }
                
            },
            function (html) { },
            false
        );    
    },
    ui: {
        update: function()
        {
            console.log("planner.mech.ui.update()");
            //alert("U" + $("#uimechname").text());
            id = planner.save_id(planner.mech.player);
            
            if ( planner.mech.mechtype != "" )
                // $("#uimechname").text(planner.mech.mechtype);
                $("#uimechname, #uimechnameof" + id).text(planner.mech.mechtype);
            else
                $("#uimechname, #uimechnameof" + id).text("'Mech: n/a");
                
            if ( planner.mech.speed > 0 )
                $("#uispeed, #uispeedof" + id).html("&#8776;" + planner.mech.speed + " km/h");
            else
                $("#uispeed, #uispeedof" + id).text("Speed: n/a");
            
            if (planner.mech.weapons.length > 0)
                $("#uiweapons, #uiweaponsof" + id).html(planner.mech.pretty_weapons().join(", "))
            else
                $("#uiweapons, #uiweaponsof" + id).text("Weapons: n/a");
                
            if (planner.mech.modules.length > 0)
                $("#uimodules, #uimodulesof" + id).html(planner.mech.modules.join(", "))
            else
                $("#uimodules, #uimodulesof" + id).text("Modules: n/a");
                
            if (planner.mech.equipment.length > 0)
                $("#uiequipment, #uiequipmentsof" + id).html(planner.mech.equipment.join(", "))
            else
                $("#uiequipment, #uiequipmentsof" + id).text("Equipment: n/a!");
        }
    }
});

